#include <QString>
#include <iostream>
#include "fabricTreeItem.h"
#include "particleTreeItem.h"
#include "springTreeItem.h"

FabricTreeItem::FabricTreeItem(QTreeWidgetItem *_parentItem, Fabric *_fabric) : TreeItem(_parentItem), fabric(_fabric){
    setExpanded(true);

    QString str = "Tecido ";
    str.append(QString::number(fabric->getID()));
    setText(0, str);

    updateParticles();
    updateSprings();

}

FabricTreeItem::~FabricTreeItem(){
    for(int i = 0; i < childCount(); i++)
        delete child(i);
}

void FabricTreeItem::updateParticles(){
    QTreeWidgetItem *item = new TreeItem(QString::fromUtf8("Partículas"), this);

    const std::vector<Particle *> &particles = fabric->getParticles();
    for(unsigned int i = 0; i < particles.size(); i++)
    {
        new ParticleTreeItem(item, particles[i]);
    }
}

void FabricTreeItem::updateSprings(){
    QTreeWidgetItem *item = new TreeItem(QString::fromUtf8("Molas"), this);

    const std::vector<Spring *> &springs = fabric->getSprings();
    for(unsigned int i = 0; i < springs.size(); i++)
    {
        new SpringTreeItem(item, springs[i]);
    }
}
